# 创建向量

numeric_vector <- c(1, 2, 3, 4, 5)  # 数值型向量
numeric_vector

character_vector <- c("apple", "banana", "cherry", "date")  # 文本型向量
character_vector

logical_vector <- c(TRUE, FALSE, TRUE, FALSE, TRUE)     # 逻辑型向量
logical_vector

length(numeric_vector)  # 查询向量长度
length(character_vector)    # 查询向量长度
length(character_vector)    # 查询向量长度
length(logical_vector)  

# 创建矩阵

matrix_example <- matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 9), nrow = 3, ncol = 3)  # 创建一个3x3的矩阵  
matrix_example

text_matrix_example <- matrix(c("apple", "banana", "cherry", "date", "elderberry", "fig"), nrow = 2, ncol = 3)  # 创建一个文本型的矩阵  
text_matrix_example
 
text_matrix_example_byrow <- matrix(c("apple", "banana", "cherry", "date", "elderberry", "fig"), nrow = 2, ncol = 3, byrow = TRUE)  # 创建一个文本型的矩阵，元素按照行优先的形式进行排列 
text_matrix_example_byrow

# 创建数组
array_example <- array(data = c(1, 2, 3, 4, 5, 6, 7, 8, 9), dim = c(3, 3))  # 创建一个3x3的数组
array_example

array_3d <- array(data = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20), dim = c(3, 3, 3))    # 创建一个3x3x3的数组  
array_3d

# 创建数据框（先创建几个向量，然后将向量组合成一个数据框）
name <- c("Alice", "Bob", "Charlie", "David")  
age <- c(25, 30, 35, 40)  
gender <- c("Female", "Male", "Male", "Male")  
score <- c(85, 90, 95, 100)  
 
df <- data.frame(Name = name, Age = age, Gender = gender, Score = score)  
df

# 创建一个复杂的列表  
my_complex_list <- list(  
  "apple",   
  "banana",   
  "cherry",   
  list("date", "elderberry"),   
  c(1, 2, 3),   
  matrix(c(1, 2, 3, 4, 5, 6), nrow = 2),   
  data.frame(Name = c("Alice", "Bob"), Age = c(25, 30)),  
  TRUE  
)  
my_complex_list

# 查看数据结构
class(numeric_vector)
class(matrix_example)
class(df)
class(array_3d)
class(my_complex_list)
